@extends('admin.layouts.admin')
@section('header') <link rel="stylesheet" href="{{ asset('admin/style/admin.css') }}" media="all"> @endsection
@section('content')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline lay-search">
                            <input type="text" name="name" placeholder="名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        @include('admin.layouts._layout.form_search')
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    @include('admin.layouts._layout.form_button_top')
                </div>

                <table id="LAY-form" lay-filter="LAY-form"></table>

                <script type="text/html" id="tpl_name">
                    <span>@{{d.html}} @{{d.name}}</span>
                </script>

                <script type="text/html" id="tpl_category">
                    <span>@{{d.has_one_category.name}}</span>
                </script>

                <script type="text/html" id="table-controller">
                    @include('admin.layouts._layout.form_button')
                </script>
            </div>
        </div>
    </div>
    <form id="destroy_form" method="post">{{ csrf_field() }} {{ method_field('DELETE') }}</form>
@endsection
@section('scripts')
    <script>
        layui.config({
            base: '../' //静态资源所在路径
        }).use([ 'table', 'form'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table
                ,views = layui.view;

            var _actions = 'article';
            //
            /**
             * 表格列表
             */
            var cols = [[
                {type: "checkbox", fixed: "left"},
                {type:  "numbers", title: "ID"}
                ,{field: "id", title: "文章ID"}
                ,{field: "cid", title: "栏目ID",templet:"#tpl_category"}
                ,{field: "name", title: "名称"}
                ,{field: "order", title: "排序", edit: 'text'}
                ,{field: "created_at", title: "创建时间", sort : !0}
                ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-controller'}]];
            var initTable = Common.initTable(cols);

            /**
             * 监听搜索
             */
            form.on('submit(LAY-search)', function(data){
                Common.search(data,1);
            });

            /**
             * 监听重置
             */
            form.on('submit(LAY-reset)', function(data){
                $('.lay-search input').val('');
                $(".layui-form select").find("option:first").prop("selected", true);
                form.render();
                Common.search(data,2);
            });

            /**
             * 监听锁定操作
             */
            form.on('checkbox(lockDemo)', function(obj){
                // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
                var url = "{:url('SystemConfigCategory/setStatus')}?id=" + this.value;
                Common.setStatus(url)
            });
            /**
             * 监听排序
             */
            table.on('sort(LAY-form)', function(obj){
                Common.sort(obj);
            });

            /**
             * 监听单元格编辑
             **/
            table.on('edit(LAY-form)', function(obj){
                var postUrl = "/admin/"+ _actions + "/update/" + obj.data.id
                Common.editCols(postUrl,obj);
            });

            /**
             * 操作监听 删除和修改
             * @controllers del edit
             */
            table.on("tool(LAY-form)", function(e) {
                if ("del" === e.event) {
                    var postUrl = "/admin/" + _actions + "/destroy";
                    Common.deleteTable(postUrl,e);
                }else if ("edit" === e.event) {
                    var type = 2;
                    var title = '编辑';
                    var modalUrl = "/admin/" + _actions + "/edit/" + e.data.id;
                    var postUrl = "/admin/" + _actions + "/update/" + e.data.id;
                    var width = '800px';
                    var height = '650px';
                    Common.editTable(type, title, modalUrl, postUrl, width, height);
                }
            });

            /**
             * 事件 添加和批量删除
             * @controllers {batchdel: batchdel, add: add}
            */
            $('.layui-btn.layuiadmin-btn-search').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                batchdel: function(){
                    var postUrl = "/admin/" + _actions + "/destroy";
                    Common.batchDeleteTable(postUrl);
                }
                ,add: function(){
                    var title = '添加';
                    var modalUrl = "/admin/" + _actions + "/create";
                    var postUrl = "/admin/" + _actions + "/store";
                    var width = '800px';
                    var height = '650px';
                    Common.addTable(title, modalUrl, postUrl, width, height);
                }
            };
        });//use

    </script>
@stop
